﻿@{
    ViewBag.Title = "";
    Layout = "~/Views/Shared/_Form.cshtml";
    //报表链接
    //var reportUrl = SysConfigReader.OrgReportLink("OutpatientDailyFee");
    var reportUrl = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportUrl");
    var reportSystemCode = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportSystemCode");
}

<div class="rows">
    <div class="panel panel-default">
        <table class="form">
	        <tr>
		        <th class="formTitle">交账列表：</th>
		        <td class="formValue">
			        <input id="jzlb" name="jzlb" type="text" autocomplete= "off" class="form-control" />
		        </td>
		        <th class="formTitle">开始日期：</th>
		        <td class="formValue">
			        <input id="kssj" type="text" class="form-control input-wdatepicker form-an" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" disabled="disabled"/>
		        </td>
		        <th class="formTitle">结束日期：</th>
		        <td class="formValue">
			        <input id="jssj" type="text" class="form-control input-wdatepicker form-an" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")" />
		        </td>
		        <td class="formValue" style="padding-left: 20px;">
			        <input type="button" id="btn_search" onclick="submit();" class="btn btn-primary btn-md" value="查询" style="width: 55px"/>
		        </td>
		        <td class="formValue" style="padding-left: 20px;">
			        <input type="button" id="btn_turnInFee" onclick="turnInFee();" class="btn btn-primary btn-md" value="确认交账" style="width: 55px"/>
		        </td>
		        <td class="formValue"></td>
	        </tr>
        </table>
    </div>
</div>

<div class="ui-layout" id="layout" style="height:100%;width:100%;">
    <iframe class="ui-layout-center" style="width:100%;" id="iframerightiframerightiframerightttt" name="iframerightiframerightiframerightttt"
            scrolling="auto" allowtransparency="true" frameborder="0"></iframe>
</div>
<script type="text/javascript">
	var isbd = 0;
	//治疗项目选择浮层绑定
	$('#jzlb').newtouchBatchFloatingSelector({
		width: 600,
		height: 200,
		caption: "选择交账",
		clickautotrigger: true,
		url: "/ReportManage/Report/turnInFeeSelect",
		ajaxparameters: function ($thisinput) {
			//var keyword = $thisinput.val().trim();
			var jzlb = $("#jzlb").val();
			return "keyword=" + jzlb;
		},
		itemdbclickhandler: function ($thistr, $thisinput) {
			if (!!$thistr.attr('data-Id')) {
				if ($thistr.attr('data-kssj') !== "" && $thistr.attr('data-kssj') !== undefined && $thistr.attr('data-kssj') !== null) {
					$('#kssj').val($thistr.attr('data-kssj'));
				}
				if ($thistr.attr('data-jssj') !== "" && $thistr.attr('data-jssj') !== undefined && $thistr.attr('data-jssj') !== null) {
					$('#jssj').val($thistr.attr('data-jssj'));
				} else {
					$('#jssj').val($.getDateTime());
				}
				$("#btn_search").attr("disabled", "disabled");
				$("#btn_turnInFee").attr("disabled", "disabled");
				submit($thistr.attr('data-Id'));
			}
		},
		colModel: [
			{ label: 'ID', name: 'Id', hidden: true },
			{ label: '开始时间', name: 'kssj', width: 180 },
			{ label: '结束时间', name: 'jssj', width: 180 },
			{ label: '总金额', name: 'zje', width: 80 },
			{ label: '现金支付', name: 'xjzf', width: 80 }
		]
	});
	function submit(jzid) {
		if (!jzid) {
			jzid = null;
		}
        if ($('#kssj').val().length == 0) {
            $.modalAlert("缺少开始时间", "error");
            return;
        }
        if ($('#jssj').val().length == 0) {
            $.modalAlert("缺少结束时间", "error");
            return;
        }
        if ($('#kssj').val() > $('#jssj').val()) {
            $.modalAlert("开始时间不能大于结束时间", "error");
            return;
        }
        
        var url = getUrl();
        var usercode = '@ViewBag.usercode';
        url += "&kssj=" + $('#kssj').val();
        url += "&jssj=" + $('#jssj').val();
        url += "&doctor=" + usercode;
        if (jzid != null) {
            url += "&jzid=" + jzid;
        } else {
            url += "&jzid=" + "";
        }
        var orgId = '@ViewBag.orgId';
        url += "&orgId=" + orgId;
        setTimeout("$.loading(true, '正在请求报表页面...');", 10);
        $("#iframerightiframerightiframerightttt").attr('src', url);

    }

    $("#iframerightiframerightiframerightttt").load(function () {
        $.loading(false);
    });

    function turnInFee() {
	    if ($('#kssj').val().length == 0) {
		    $.modalAlert("缺少开始时间", "error");
		    return;
	    }
	    if ($('#jssj').val().length == 0) {
		    $.modalAlert("缺少结束时间", "error");
		    return;
	    }
	    if ($('#kssj').val() > $('#jssj').val()) {
		    $.modalAlert("开始时间不能大于结束时间", "error");
		    return;
	    }
	    $.ajax({
		    type: "POST",
		    url: "/ReportManage/Report/turnInFee",
		    data: { kssj: $('#kssj').val(), jssj: $('#jssj').val() },
		    dataType: "json",
		    success: function() {
		    	$.modalAlert("交账成功", "success");
			    return;
		    }
	    });
    }
    $(function () {
	    var h = $(window).height() - 55;
        $('#layout iframe').css('height', h);
        $("#kssj").val('@ViewBag.kssj');
	    $("#jssj").val($.getTime());
        setTimeout(function () { submit(); }, 100);
    });

    function getUrl() {
        var srcUrl = '@Html.Raw(reportUrl)';
        srcUrl += "?tempCode=31" + "&systemCode=" + '@reportSystemCode';
        return srcUrl;
    }

</script>